from sqlalchemy import create_engine
import pymysql
import pandas as pd


class mysql_db:
    def __init__(self, database:str):
        user="user_rpa"
        password="123456"
        # host="192.168.8.10" # 西安数据库
        host="10.20.30.1" # 河津数据库
        port=3306
        if not database:
            raise("请输入数据库")
        self.engine = create_engine(f'mysql+pymysql://{user}:{password}@{host}:{port}/{database}?charset=utf8mb4')
        self.conn = pymysql.connect(user=user, password=password, host=host, port=port, database=database, charset='utf8mb4')
        
        self.cur = self.conn.cursor()

    def read_data_by_pd(self, sql):
        query = pd.read_sql(sql, con=self.engine)
        return query